package com.easyjava.builder.strategy.impl;

import com.easyjava.bean.FieldInfo;
import com.easyjava.bean.TableInfo;
import com.easyjava.builder.strategy.inf.MapperXmlStrategy;
import java.io.BufferedWriter;
import java.io.IOException;

/**
 * 单条插入
 */
public class XmlFieldInsertImpl implements MapperXmlStrategy {

    @Override
    public void generateMapperXml(TableInfo tableInfo, BufferedWriter bw) throws IOException {
        FieldInfo field = null;
        for (FieldInfo fieldInfo : tableInfo.getFieldList()) {
            if (fieldInfo.getAutoIncrement() != null && fieldInfo.getAutoIncrement()) {
                field = fieldInfo;
                break;
            }
        }

        bw.write("\t<!--插入（匹配有值的字段）-->\n");
        CommonXmlImpl.commonXml(tableInfo, bw, CommonXmlImpl.NAME_INSERT, field);
    }
}
